#include <iostream>
short addressBus;
short dataBus;
bool readWrite;

using namespace std;

class IClockable
{
    public:
    void ClockAddressBus();
    void ClockDataBus();
};

class MC6809E : public IClockable
{
public:
    short cpuAddressBus;
    short cpuDataBus;
    int programCounter;
    int nrofCycles;

    MC6809E()
    {
        cpuAddressBus = 0;
        cpuDataBus = 0;
        programCounter = 0;
        nrofCycles = 0;
    }

    void ConnectAddressBus(short bus)
	{
		cpuAddressBus = bus;
	}

    void ConnectDataBus(short bus)
	{
		cpuDataBus = bus;
	}

    void ClockAddressBus()
    {
        nrofCycles++;
    }

    void ClockDataBus()
    {

    }

};

class MC6847 : public IClockable
{
public:
    short vdgAddressBus;
    short vdgDataBus;
    int addressCounter;

    MC6847()
    {
        vdgAddressBus = 0;
        vdgDataBus = 0;
        addressCounter = 0;
    }

    void ConnectAdressBus(short bus)
	{
		vdgAddressBus = bus;
	}

    void ConnectDataBus(short bus)
	{
		vdgDataBus = bus;
	}

//public:
    void ClockAddressBus()
    {

    }

    void ClockDataBus()
    {

    }

};

class MC6883
{
public:
    short samAddressBus;
    short extAddressBus;
    short addressCounter;

    IClockable Suckers[];
    IClockable Rulers[];

    MC6809E mpu;
    MC6847 vid;

    MC6883()
    {
        samAddressBus = 0;
        extAddressBus = 0;
        addressCounter = 0;

//        Suckers = new IClockable[8];
//        Rulers = new IClockable[8];

    }

    void AddSucker(IClockable q)
    {
        Suckers[0] = q;
    }

    void AddRuler(IClockable e)
    {
        Rulers[0] = e;
    }

    void ConnectAdressBus(short bus)
	{
		samAddressBus = bus;
	}

    void ConnectExtAddressBus(short bus)
    {
        extAddressBus = bus;
    }

    void ConnectMemory()
    {

    }

    void PowerIn()
    {

        //Rulers[0].ClockAddressBus();
        mpu.ClockAddressBus();

        addressCounter++;

    }

};

int main()
{
    cout << "CoCoon Core Pilot" << endl;

    MC6883 sam;
    sam.ConnectAdressBus(addressBus);

    MC6847 vdg;
    vdg.ConnectAdressBus(sam.extAddressBus);
    vdg.ConnectDataBus(dataBus);

    MC6809E cpu;
    cpu.ConnectAddressBus(addressBus);
    cpu.ConnectDataBus(dataBus);

    sam.AddRuler(cpu);
    sam.AddSucker(vdg);
    //sam.ConnectMemory(memory)
	readWrite = 0;


    //test
    sam.mpu = cpu;
    sam.vid = vdg;

    for(int i = 0; i < 1000; i++)
    {
        sam.PowerIn();
    }

    int n = cpu.nrofCycles;
    //int s = sam.addressCounter;

    cout << "nr of Cycles: " << n << endl;

    return 0;
}
